package cn.edu.nuc.ssm.controller.sys;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.edu.nuc.ssm.domain.Order;
import cn.edu.nuc.ssm.service.interfaces.ShopCarService;

@Controller
@RequestMapping("shopcar")
public class ShopCarController {
    @Autowired
	private ShopCarService service;
    
    //添加购物车
    @RequestMapping(value="add",method=RequestMethod.POST)
    public String insert(Order order){
    	int result = service.insert(order);
    	if(result>0){
    		return "redirect:list?userid="+order.getUserid();
    	}
    	return null;
    }
    
    //购物车列表(和电影表联系。)
    @RequestMapping(value="list",method=RequestMethod.GET)
    public String list(int userid,Model model){
    	List<Order> list = service.list(userid);
    	if(list.size()>0){
    		model.addAttribute("film", list);
    		return "forward:/shopcarlist.jsp";
    	}
    	return "forward:/select.jsp";
    }
    
    //移除购物车
    @RequestMapping(value="delete",method=RequestMethod.GET)
    public String delete(int orderid,int userid){
    	int result = service.delete(orderid);
    	if(result>0){
    		return "redirect:list?userid="+userid;
    	}
    	return null;
    }
}
